//
//  TTHomeTableViewCell.swift
//  WeiBo
//
//  Created by 涂永江 on 2017/6/8.
//  Copyright © 2017年 涂永江. All rights reserved.
//

import UIKit
import SnapKit

class TTHomeTableViewCell: UITableViewCell {

    
    //记录homeToolBar的约束
    var hometoolContraint:Constraint?
 
    var satuesModel:TTStatuesViewModel?
    {
        didSet{
        
              homeOriginalView.stusModel = satuesModel
              homeToolBar.stusModel = satuesModel
            
         
            //移除top的约束homeToolBar
            hometoolContraint?.deactivate()
            //有转发微博
           if satuesModel?.statues?.retweeted_status != nil{
            
              //retweeted_statusView显示
               homeRetweetView.isHidden = false
            
          
            //设置约束homeToolBar
            homeToolBar.snp.makeConstraints({ (make) in
                
               hometoolContraint = make.top.equalTo(homeRetweetView.snp.bottom).constraint
                
                 homeRetweetView.stutesModel = satuesModel
            })
         
            }else
           {
            //retweeted_statusView隐藏
             homeRetweetView.isHidden = true
            
             //设置约束homeToolBar
            homeToolBar.snp.makeConstraints({ (make) in
              hometoolContraint = make.top.equalTo(homeOriginalView.snp.bottom).constraint
            })
            
            }
        
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
     
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //懒加载控件
    
    private lazy var homeOriginalView:TTHMHomeOriginalView = TTHMHomeOriginalView()
    private lazy var homeRetweetView:TTHMHomeRetweetView = TTHMHomeRetweetView()
    private lazy var homeToolBar:TTHMHomeToolBar = TTHMHomeToolBar()
    
      func setUI()
     {
         contentView.addSubview(homeOriginalView)
         contentView.addSubview(homeToolBar)
         contentView.addSubview(homeRetweetView)
        
        homeOriginalView.snp.makeConstraints { (make) in
          make.top.equalTo(contentView).offset(magin)
          make.leading.trailing.equalTo(contentView)
       
        }
        homeRetweetView.snp.makeConstraints { (make) in
            make.top.equalTo(homeOriginalView.snp.bottom)
            make.leading.trailing.equalTo(homeOriginalView)
        }
        
        homeToolBar.snp.makeConstraints { (make) in
          hometoolContraint = make.top.equalTo(homeRetweetView.snp.bottom).constraint
            make.trailing.leading.equalTo(contentView)
            make.height.equalTo(35)
            make.bottom.equalTo(contentView)
        }
        
    }
    
}
